<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('师傅列表')" />
	<th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="gray-bg">
	<div class="ui-layout-center">
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 search-collapse">
					<form id="user-form">
						<input type="hidden" name="roleId" value="101">
						<div class="select-list">
							<ul>
								<li>
									师傅名称：<input type="text" name="userName" onkeyup="$.table.search()"/>
								</li>
								<li>
									手机号码：<input type="text" name="phonenumber" onkeyup="$.table.search()"/>
								</li>
								<li>
									用户状态：<select name="status" th:with="type=${@dict.getType('sys_normal_disable')}" onchange="$.table.search()">
										<option value="">所有</option>
										<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
									</select>
								</li>
								<li>
								    <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;全部</a>
								</li>
							</ul>
						</div>
					</form>
				</div>
				
		        <div class="btn-group-sm" id="toolbar" role="group">
		        	<a class="btn btn-success" onclick="workerAdd()">
		                <i class="fa fa-plus"></i> 新增
		            </a>
		        </div>
		        
		        <div class="col-sm-12 select-table table-striped">
				    <table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: bootstrap-table-editable-js" />
	<script th:inline="javascript">

		var prefix = ctx + "hh/user";

		$(function() {
		    var options = {
		        url: prefix + "/userList",
		        removeUrl: ctx + "system/user/remove",
				showSearch: false,
				showRefresh: false,
				showToggle: false,
				showColumns: false,
                modalName: "师傅信息",
		        columns: [
		        {
		            field: 'userId',
		            title: '用户ID',
					visible: false
		        },
                {
                    title: "序号",
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
		        {
		            field: 'userName',
		            title: '师傅名称'
		        },
		        {
		            field: 'phonenumber',
		            title: '手机'
		        },
		        {
		        	title: '用户状态',
		        	align: 'center',
		        	formatter: function (value, row, index) {
		        		return statusTools(row);
		        	}
		        },
		        {
		            field: 'remark',
		            title: '备注',
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
						actions.push('<a class="btn btn-default btn-xs ' + '" href="javascript:void(0)" onclick="resetPwd(' + row.userId + ')"><i class="fa fa-key"></i>重置密码</a> ');
		                actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="workerEdit(' + row.userId + ')"><i class="fa fa-edit"></i>编辑</a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.userId + '\')"><i class="fa fa-remove"></i>删除</a> ');
		                return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
			$.table.search();
		});

		$('#bootstrap-table').on('page-change.bs.table', function (e,number, size) {
			window.scrollTo(0,0);
		});

        /* 师傅管理-新增 */
		function workerAdd() {
            layer.open({
                type: 2,
                area: ['600px', '400px'],
                fix: false,
                shade: 0.3,
                title: '新增水电师傅',
                content: prefix + "/workerAdd",
                btn: [],
                end: function () {
                    $.table.refresh();
                }
            });
        }

        /* 师傅管理-编辑信息 */
        function workerEdit(userId) {
            layer.open({
                type: 2,
                area: ['600px', '400px'],
                fix: false,
                shade: 0.3,
                title: '修改信息',
                content: prefix + "/workerEdit/" + userId,
                btn: [],
                end: function () {
                    $.table.refresh();
                }
            });
        }

		/* 用户管理-重置密码 */
		function resetPwd(userId) {
		    var url = ctx + 'system/user/resetPwd/' + userId;
		    $.modal.open("重置密码", url, '800', '300');
		}
		
		/* 用户状态显示 */
		function statusTools(row) {
		    if (row.status == 1) {
    			return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
    		} else {
    			return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
    		}
		}
		
		/* 用户管理-停用 */
		function disable(userId) {
			$.modal.confirm("确认要停用用户吗？", function() {
				$.operate.post(ctx + "system/user/changeStatus", { "userId": userId, "status": 1 });
		    })
		}

		/* 用户管理启用 */
		function enable(userId) {
			$.modal.confirm("确认要启用用户吗？", function() {
				$.operate.post(ctx + "system/user/changeStatus", { "userId": userId, "status": 0 });
		    })
		}

	</script>
</body>
</html>